import http from './http.js'

export const login = (username, password) => {
	return http.post('/api/user/login', {
		username,
		password
	})
}

export const getCartList = () => {
	return http.get('/api/cart/list')
}

export const cartAdd = (id, num) => {
	return http.post('/api/cart/add', {
		gid: id,
		num: num
	})
}

export const cartRemove = (id) => {
	return http.post('/api/cart/remove', {
		id
	})
}

export const cartIncrease = (id, gid, num) => {
	return http.post('/api/cart/increase', {
		id,
		num,
		gid
	})
}

export const cartDecrease = (id, num) => {
	return http.post('/api/cart/decrease', {
		id,
		num
	})
}
export const getDefaultAddress = () => {
	return http.get('/api/address/default')
}

export const getAddress = (id = '') => {
	if (id === '') return http.get('/api/address/list')
	else return http.get('/api/address', {
		id
	})
}

export const addAddress = (param) => {
	return http.post('/api/address/add', param)
}
export const delAddress = (id) => {
	return http.post('/api/address/remove', {
		id
	})
}
export const editAddress = (param) => {
	return http.post('/api/address/edit', param)
}
export const getProvince = () => {
	return http.get('/api/pcct/province')
}
export const getCity = (id) => {
	return http.get('/api/pcct/city', {
		id
	})
}
export const getCounty = (id) => {
	return http.get('/api/pcct/county', {
		id
	})
}
export const getTown = (id) => {
	return http.get('/api/pcct/town', {
		id
	})
}
export const getSettle = goods => {
	return http.post('/api/order/settle', {
		goods
	})
}
export const getOrderDetail = id => {
	return http.get('/api/admin/order',{id})
}
export const createOrder = param => {
	return http.post('/api/order/create', param)
}
export const getUserInfo = () => {
	return http.get('/api/user/info')
}
export const getOrderList = (param) => {
	return http.get('/api/order/list', param)
}
export const getOrderPrice = oid => {
	return http.get('/api/order/price', {
		oid
	})
}
export const pay = oid => {
	return http.post('/api/order/pay', {
		oid:parseFloat(oid)
	})
}
export const closeOrder = (oid) => {
	return http.post('/api/order/cancel',{oid})
}
export const getCollection = () => {
	return http.get('/api/collection/list')
}
export const getType = (pId = 1) => {
	return http.get('/api/category/subAll',{pId})
}
export const postReceiving = id => {
	return http.post('/api/admin/order/receiving',{id})
}